
ADD_DEFINITIONS( -Wall -O0 -ggdb )
#ADD_DEFINITIONS( -Wall -O2 )

INCLUDE( ../gensrc/FindGLIB2.cmake )
INCLUDE( ../gensrc/FindUUID.cmake )

INCLUDE_DIRECTORIES(
${PROJECT_SOURCE_DIR}/../gensrc
${GLIB2_INCLUDE_DIRS}
${UUID_INCLUDE_DIRS}
)

LINK_DIRECTORIES( ${PROJECT_SOURCE_DIR}/../gensrc )

################################################################################
# source: http://www.cmake.org/Wiki/CMakeMacroAddCxxTest
#         http://www.cmake.org/Wiki/CMake_Testing_With_CTest
#
# Make sure testing is enabled
ENABLE_TESTING()

# Use Python interpreter
FIND_PACKAGE( PythonInterp )

# Path to the cxxtestgen.py script
#SET(CXXTESTGEN ${CMAKE_SOURCE_DIR}/thirdparty/cxxtest/cxxtestgen.py)
SET( CXXTESTGEN /usr/bin/cxxtestgen.py )

################################################################################

MACRO(ADD_CXXTEST NAME)
  IF(PYTHONINTERP_FOUND)
    ADD_CUSTOM_COMMAND(
      OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${NAME}.cpp
      COMMAND
        ${PYTHON_EXECUTABLE} ${CXXTESTGEN}
        --runner=ErrorPrinter
        -o ${NAME}.cpp ${ARGN}
      DEPENDS ${ARGN}
      WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    )
  ENDIF(PYTHONINTERP_FOUND)

  ADD_EXECUTABLE(${NAME} ${CMAKE_CURRENT_SOURCE_DIR}/${NAME}.cpp ${ARGN})
  TARGET_LINK_LIBRARIES(${NAME} golf)

  ADD_TEST(${NAME} ${NAME})
ENDMACRO(ADD_CXXTEST)

################################################################################

MACRO(ADD_CXXTEST_SEP NAME)
  IF(PYTHONINTERP_FOUND)
    # generate the parts
    FOREACH(_PART ${ARGN})
      GET_FILENAME_COMPONENT(_NAME ${_PART} NAME)
      GET_FILENAME_COMPONENT(_NAME_WE ${_PART} NAME_WE)
      ADD_CUSTOM_COMMAND(
        OUTPUT ${_NAME_WE}.cpp
        COMMAND
          ${PYTHON_EXECUTABLE} ${CXXTESTGEN}
          --part
          -o ${_NAME_WE}.cpp
          ${_NAME}
        DEPENDS ${_PART}
        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
      )
    ENDFOREACH(_PART)

    # generate the runner
    ADD_CUSTOM_COMMAND(
      OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${NAME}_runner.cpp
      COMMAND
        ${PYTHON_EXECUTABLE} ${CXXTESTGEN}
        --runner=ErrorPrinter --root
        -o ${NAME}_runner.cpp
      WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    )
  ENDIF(PYTHONINTERP_FOUND)

  # enumerate all generated files
  SET(PARTS ${CMAKE_CURRENT_SOURCE_DIR}/${NAME}_runner.cpp)
  FOREACH(_PART ${ARGN})
    GET_FILENAME_COMPONENT(_PART_WE ${_PART} NAME_WE)
    SET(PARTS ${PARTS} ${_PART_WE}.cpp)
  ENDFOREACH(_PART)

  ADD_EXECUTABLE(${NAME} ${PARTS})

  ADD_TEST(${NAME} ${NAME})
ENDMACRO(ADD_CXXTEST_SEP)

################################################################################

ADD_CXXTEST( testRating testRating.h )
#ADD_DEPENDENCIES(testRating ${PROJECT_SOURCE_DIR}/../gensrc/Rating.h)
ADD_CXXTEST( testGolfhole testGolfhole.h )
ADD_CXXTEST( testTeebox testTeebox.h )
